package com.minisoft.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.PageUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.junit.Test;

import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author JueSu
 * @description: TODO
 * @date 2021/11/3 9:44
 */
public class CheckData {

    public static String DB_CENTER = "center-pro";
    public static String DB_YDAC = "ydac-pro";

    public static Map<String,Integer> roleMap = new HashMap<>();

    String beginDate = "2021-12-18";
    String endDate = null;
    String fileName;

    static {
        roleMap.put("置业顾问",2011);
        roleMap.put("销售主管",2012);
        roleMap.put("销售经理",2015);
    }

    @Test
    public void testQueryCondition() {
        List<String> mobiles = FileUtil.readUtf8Lines(getClass().getResource("/mobileFilter.txt"));
        int pageSize = 30;
        int totalPage = PageUtil.totalPage(mobiles.size(), pageSize);
        for (int i = 0;i< totalPage;i++) {
            int start = PageUtil.getStart(i, pageSize);
            int end = PageUtil.getEnd(i, pageSize);
            if (end > mobiles.size()) {
                end = mobiles.size();
            }
            List<String> subList = mobiles.subList(start, end);
            //"发送mq" and ()
            System.out.println("\"cpInfoDto init\" and (" + CollUtil.join(subList," or ")+")");
        }
    }

    @Test
    public void testExactMsg(){
        String prefix = DateUtil.format(new Date(),DatePattern.PURE_DATE_PATTERN);
        List<String> fileLogs = new ArrayList<>();
        List<String> msgLogs = new ArrayList<>();
        Map<String,Boolean> msgMap = new HashMap<>();

        for (int i = 0;i < 1;i++) {
            String filename = StrUtil.format("/esRaw/20211221-{}.txt",i);
            String esResult = FileUtil.readString(getClass().getResource(filename),"utf-8");
            JSONObject esJson = JSONUtil.parseObj(esResult);
            JSONArray hits = esJson.getByPath("hits.hits", JSONArray.class);
            hits.forEach(item -> {
                JSONObject obj = (JSONObject) item;
                String message = obj.getByPath("_source.message", String.class);
                String mqKeyStr = "cpInfoDto init: ";
                int index = message.indexOf(mqKeyStr);
                if (index != -1) {
                    String msg = message.substring(index + mqKeyStr.length());
                    fileLogs.add(msg);
                    if (!msgMap.containsKey(msg)) {
                        msgMap.put(msg,true);
                        msgLogs.add(msg);
                    }
                }
            });
            Console.log("解释完 {} 后，消息长度为：{},去重后为: {}",filename,fileLogs.size(),msgLogs.size());
        }
        //输出到文件
        fileName = DateUtil.format(new Date(), "yyyy-MM-ddHHmmss")+".txt";
        File file = new File("generateExactMsg/" + fileName);
        FileUtil.writeLines(msgLogs,file, StandardCharsets.UTF_8);
    }
    @Test
    public void testExactMsg2(){
        String prefix = DateUtil.format(new Date(),DatePattern.PURE_DATE_PATTERN);
        List<String> fileLogs = new ArrayList<>();
        List<String> msgLogs = new ArrayList<>();
        Map<String,Boolean> msgMap = new HashMap<>();

        for (int i = 0;i < 1;i++) {
            String filename = StrUtil.format("/esRaw/20211221-{}.txt",i);
            String esResult = FileUtil.readString(getClass().getResource(filename),"utf-8");
            JSONObject esJson = JSONUtil.parseObj(esResult);
            JSONArray hits = esJson.getByPath("hits.hits", JSONArray.class);
            hits.forEach(item -> {
                JSONObject obj = (JSONObject) item;
                String message = obj.getByPath("_source.message", String.class);
                String mqKeyStr = "收到埋点信息：";
                int index = message.indexOf(mqKeyStr);
                if (index != -1) {
                    String msg = message.substring(index + mqKeyStr.length());
//                    Console.log(msg);
                    fileLogs.add(msg);
                    if (!msgMap.containsKey(msg)) {
                        msgMap.put(msg,true);
                        msgLogs.add(msg);
                    }
                    JSONObject msgJson = JSONUtil.parseObj(msg);
                    JSONObject properties = msgJson.getJSONObject("properties");
                    System.out.println(properties.getStr("openId"));
                }
            });
            Console.log("解释完 {} 后，消息长度为：{},去重后为: {}",filename,fileLogs.size(),msgLogs.size());
        }
        //输出到文件
//        fileName = DateUtil.format(new Date(), "yyyy-MM-ddHHmmss")+".txt";
//        File file = new File("generateExactMsg/" + fileName);
//        FileUtil.writeLines(msgLogs,file, StandardCharsets.UTF_8);
    }

    @Test
    public void testSaler() throws SQLException {
        List<Entity> centerResult = Db.use(DB_CENTER).query("SELECT s.staff_name,s.user_key,s.position_name,s.sale_team_id,r.sale_team_name,r.project_id,r.sale_org_id,UPPER(CONCAT(s.user_key,r.sale_org_id)) skey from sale_consultant s ,sale_team_sale_org_rel r where s.sale_team_id = r.sale_team_id and s.dimission_flag = 0 and s.position_name in ('置业顾问','销售经理','销售主管')");
        List<Entity> ydacResult = Db.use(DB_YDAC).query("SELECT s.appid,s.saleropenid,s.userkey,p.id pid,p.hfProjectId,p.sale_org_id,UPPER(CONCAT(s.userkey,p.sale_org_id)) skey from dh_project_saler s,dh_project_saler_auth a, dh_project p where s.saleropenid = a.saleropenid and a.projectid = p.Id and s.quit=0 and s.quitTime is null and a.isvalid = 1 and p.sale_org_id is not null and p.sale_org_id != '' and s.userkey is not null order by s.userkey");
        List<Entity> rsProResult = Db.use(DB_YDAC).query("SELECT * from dh_project p where p.sale_org_id is not null");

        System.out.println("centerResult:,ydacResult:"+centerResult.size()+","+ydacResult.size());
        Map<String,Entity> ydacMap = new HashMap<>();
        Map<String,Entity> ydacSaleMap = new HashMap<>();
        Map<String,Entity> rsProMap = new HashMap<>();

        List<Entity> needAddList = new ArrayList<>();

        rsProResult.forEach(item -> {
            rsProMap.put(item.getStr("sale_org_id"),item);
        });
        ydacResult.forEach(item -> {
            ydacMap.put(item.getStr("skey"),item);
            ydacSaleMap.put(item.getStr("userkey"),item);
        });
        centerResult.forEach(item -> {
            if (ydacMap.containsKey(item.getStr("skey"))){
                //存在，看下岗位是否一致
            } else {
                //不存在，看下有没有注册
                if (ydacSaleMap.containsKey(item.getStr("user_key"))) {
                    //有注册，应该补数据
                    needAddList.add(item);
                }
            }
        });

        System.out.println("需要补的顾问列表：" + needAddList.size());
        needAddList.forEach(item -> {
            System.out.println(item.filter("staff_name","user_key","position_name","project_id","sale_team_name","sale_org_id"));
            try {
                Entity rsPro = rsProMap.get(item.getStr("sale_org_id"));
                Entity saler = ydacSaleMap.get(item.getStr("user_key"));
                if (rsPro != null) {
//                    Db.use(DB_YDAC).insert(Entity.create("dh_project_saler_auth")
//                            .set("appid", rsPro.getStr("appid"))
//                            .set("saleropenid", saler.getStr("saleropenid"))
//                            .set("projectid", rsPro.getInt("Id"))
//                            .set("isvalid", 1).set("createtime",new Date())
//                            .set("roleid", roleMap.get(item.getStr("position_name")))
//                            .set("sale_team_id", item.getStr("sale_team_id"))
//                    );
                } else {
                    System.out.println("项目不存在移动案场：" + item.getStr("sale_org_id"));
                }
            } catch (Exception throwables) {
                throwables.printStackTrace();
            }
        });

    }

    @Test
    public void testSaleOrg() throws SQLException {
        List<Entity> centerResult = Db.use(DB_CENTER).query("SELECT * from sale_team_sale_org_rel");
        List<Entity> ydacResult = Db.use(DB_YDAC).query("SELECT * from dh_project");
        Map<String,Entity> ydacMap = new HashMap<>();
        ydacResult.forEach(item -> {
            ydacMap.put(item.getStr("sale_org_id"),item);
        });

        int i = 1;
        System.out.println("移动案场缺少的项目：");
        for (Entity item : centerResult) {
            if (!ydacMap.containsKey(item.getStr("sale_org_id"))) {
                System.out.println(StrUtil.format("{}：{},{},{}",i++,item.getStr("sale_team_id")
                        ,item.getStr("sale_team_name"),item.getStr("sale_org_id")));
            }
        }

    }

    private void compareUserid(List<Entity> centerResult,List<Entity> ydacResult) {
        log("centerResult:{},ydacResult:{}",centerResult.size(),ydacResult.size());
        Map<String,Entity> ydacMap = new HashMap<>();

        List<String> ydacLessUsers = new ArrayList<>();
        List<String> ydacUserSql = new ArrayList<>();
        List<String> qmyxUserSql = new ArrayList<>();
        List<String> saleUserSql = new ArrayList<>();
        List<String> userids = new ArrayList<>();

        ydacResult.forEach(item -> {
            ydacMap.put(item.getStr("userid"),item);
        });

        centerResult.forEach(item -> {
            if (ydacMap.containsKey(item.getStr("customer_id"))){
                //存在，看下到访时间是否一样，不一样则刷新
            } else {
                //不存在，需要补数，刷新到访时间
                ydacLessUsers.add(StrUtil.format("{}\t{}\t{}\t{}\t{}\t{}\t{}",
                        item.getStr("customer_id"),item.getStr("mobile"),item.getStr("visit_channel_name"),
                        item.getStr("sale_team_id"),item.getStr("create_time"),
                        item.getStr("visit_first_date"),item.getStr("update_time")));

                userids.add("'"+item.getStr("customer_id")+"'");

                //移动案场
                ydacUserSql.add(StrUtil.format("UPDATE dh_crm_saleruser u set u.createtime = '{}',u.lastmodify = '{}',u.award2time='{}',u.awardtime='{}' where userid = '{}';",
                        item.getStr("create_time"),item.getStr("update_time"),item.getStr("visit_first_date"),item.getStr("visit_first_date"),item.getStr("customer_id")));
                boolean isReportUser = !"自然到访".equals(item.getStr("visit_channel_name"));
                //全民营销
                if (isReportUser) {
                    qmyxUserSql.add(StrUtil.format("update custom_report set deal_date = '{}' where id = '{}';",
                            item.getStr("visit_first_date"),item.getStr("customer_id")));
//                    qmyxUserSql.add(StrUtil.format("update custom_sale_rel set assign_from = '{}' where cus_uuid = '{}';",
//                            item.getStr("visit_first_date"),item.getStr("customer_id")));
                    qmyxUserSql.add(StrUtil.format("update custom_follow set node_date = '{}',create_date = '{}', update_date = '{}'where cus_uuid = '{}' and noded = '到访';",
                            item.getStr("visit_first_date"),item.getStr("create_time"),item.getStr("update_time"),item.getStr("customer_id")));
                }
                //营销系统
                if (isReportUser) {
                    saleUserSql.add(StrUtil.format("UPDATE MKT_CUSTOMER set CREAT_DATE='{}',UPDATE_DATE='{}',NM_FOLLOW_DATE='{}' WHERE ID='{}';",
                            item.getStr("create_time"),item.getStr("update_time"),item.getStr("visit_first_date"),item.getStr("customer_id")));
                } else {
                    saleUserSql.add(StrUtil.format("UPDATE MKT_CUSTOMER set CREAT_DATE='{}',UPDATE_DATE='{}' WHERE ID='{}';",
                            item.getStr("create_time"),item.getStr("update_time"),item.getStr("customer_id")));
                }
                saleUserSql.add(StrUtil.format("UPDATE MKT_CUSTOMER_FOLLOW set CREAT_DATE='{}',UPDATE_DATE='{}' WHERE CUSTOMER_ID='{}' AND FOLLOW_TYPE_NAME = '来访';",
                        item.getStr("create_time"),item.getStr("update_time"),item.getStr("customer_id")));
            }
        });

        String useridStr = CollUtil.join(userids, ",");
        log("移动案场检查语句");
        log("SELECT * from dh_crm_saleruser u where u.userid in ({});",useridStr);

        System.out.println("=================================================");
        log("移动案场需要补的数据：{}" , ydacLessUsers.size());
        log("customer_id\tmobile\tvisit_channel_name\tsale_team_id\tcreate_time\tvisit_first_date\tupdate_time");
        ydacLessUsers.forEach(CheckData::log);
        log("=================================================");
        log("移动案场更新到访时间的语句：");
        ydacUserSql.forEach(CheckData::log);

        log("=================================================");
        log("全民营销更新到访时间的语句：");
        qmyxUserSql.forEach(CheckData::log);

        log("=================================================");
        log("营销系统更新到访时间的语句：");
        saleUserSql.forEach(CheckData::log);

        //输出到文件
        File file = new File("generateUseridData/" + fileName);
        FileUtil.writeLines(fileLogs,file, StandardCharsets.UTF_8);

        //输出到文件
        file = new File("generateUseridData/" + fileName.replace(".txt","-ydac.txt"));
        FileUtil.writeLines(ydacUserSql,file, StandardCharsets.UTF_8);

        //输出到文件
        file = new File("generateUseridData/" + fileName.replace(".txt","-qmyx.txt"));
        FileUtil.writeLines(qmyxUserSql,file, StandardCharsets.UTF_8);

        //输出到文件
        file = new File("generateUseridData/" + fileName.replace(".txt","-giss.txt"));
        FileUtil.writeLines(saleUserSql,file, StandardCharsets.UTF_8);
    }

    @Test
    public void testUseridByTime() throws SQLException {
        if (endDate == null) {
            //没有结束时间，则使用当前时间
            endDate = DateUtil.now();
        }
        List<Entity> centerResult = Db.use(DB_CENTER).query("SELECT om.customer_id,m.mobile,o.visit_channel_name,o.sale_team_id,o.create_time,o.visit_first_date,o.update_time from customer_opportunity o ,customer_mobile m ,customer_opportunity_map om WHERE m.customer_opportunity_id = o.customer_opportunity_id and m.sort = 0 and om.opportunity_id = o.customer_opportunity_id and o.create_time between ? and ?",beginDate,endDate);
        List<Entity> ydacResult = Db.use(DB_YDAC).query("select * from dh_crm_saleruser  WHERE createtime between ? and ?",beginDate,endDate);
        compareUserid(centerResult,ydacResult);
    }

    @Test
    public void testUseridByMobile() throws SQLException {
        String mobileStr = getMobileFilter();
        String newSql = StrUtil.format("select * from dh_crm_saleruser  WHERE mobile in ({})", mobileStr);
        List<Entity> ydacResult = Db.use(DB_YDAC).query(newSql);
        newSql = StrUtil.format("SELECT om.customer_id,m.mobile,o.visit_channel_name,o.sale_team_id,o.create_time,o.visit_first_date,o.update_time from customer_opportunity o ,customer_mobile m ,customer_opportunity_map om WHERE m.customer_opportunity_id = o.customer_opportunity_id and m.sort = 0 and om.opportunity_id = o.customer_opportunity_id and m.mobile in ({})", mobileStr);
        List<Entity> centerResult = Db.use(DB_CENTER).query(newSql);
        compareUserid(centerResult,ydacResult);
    }

    private static List<String> fileLogs = new ArrayList<>();

    private static void log(String template, Object... values) {
        Console.log(template,values);
        fileLogs.add(StrUtil.format(template,values));
    }

    @Test
    public void testUseridNotInCenter() throws SQLException {
        List<Entity> centerResult = Db.use(DB_CENTER).query("SELECT om.customer_id,m.mobile,o.visit_channel_name,o.sale_team_id,o.create_time,o.visit_first_date,o.update_time from customer_opportunity o ,customer_mobile m ,customer_opportunity_map om WHERE m.customer_opportunity_id = o.customer_opportunity_id and m.sort = 0 and om.opportunity_id = o.customer_opportunity_id and o.create_time > ?",beginDate);
        List<Entity> saleTeamOrgResult = Db.use(DB_CENTER).query("SELECT * from sale_team_sale_org_rel");
        List<Entity> ydacResult = Db.use(DB_YDAC).query("select * from dh_crm_saleruser  WHERE createtime > ?",beginDate);
        List<Entity> ydacProjectResult = Db.use(DB_YDAC).query("select * from dh_project");
        Console.log("centerResult:{},ydacResult:{}",centerResult.size(),ydacResult.size());
        Map<String,Entity> centerMap = new HashMap<>();
        Map<String,String> saleTeamOrgMap = new HashMap<>();
        Map<String,String> projOrgMap = new HashMap<>();

        List<String> centerLessUsers = new ArrayList<>();
        List<String> ydacUserSql = new ArrayList<>();
        List<String> userids = new ArrayList<>();

        saleTeamOrgResult.forEach(item -> {
            saleTeamOrgMap.put(item.getStr("sale_org_id"),item.getStr("sale_team_id"));
        });
        ydacProjectResult.forEach(item -> {
            projOrgMap.put(item.getStr("Id"),item.getStr("sale_org_id"));
        });

        centerResult.forEach(item -> {
            centerMap.put(item.getStr("mobile")+item.getStr("sale_team_id"),item);
        });

        ydacResult.forEach(item -> {
            if (centerMap.containsKey(item.getStr("mobile")+saleTeamOrgMap.get(projOrgMap.get(item.getStr("projectid"))))){
                //存在，看下到访时间是否一样，不一样则刷新
            } else {
                //不存在
                centerLessUsers.add(StrUtil.format("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}",
                        item.getStr("userid"),item.getStr("mobile"),item.getStr("customerchannel"),
                        item.getStr("projectid"),projOrgMap.get(item.getStr("projectid")),
                        saleTeamOrgMap.get(projOrgMap.get(item.getStr("projectid"))),item.getStr("createtime"),
                        item.getStr("award2time"),item.getStr("lastmodify")));

                userids.add("'"+item.getStr("userid")+"'");

                //中台
                ydacUserSql.add(StrUtil.format("UPDATE dh_crm_saleruser u set u.createtime = '{}',u.lastmodify = '{}',u.award2time='{}',u.awardtime='{}' where userid = '{}';",
                        item.getStr("create_time"),item.getStr("update_time"),item.getStr("visit_first_date"),item.getStr("visit_first_date"),item.getStr("customer_id")));
                boolean isReportUser = !"自然到访".equals(item.getStr("customerchannel"));
                if (isReportUser) {
                }
            }
        });

        String useridStr = CollUtil.join(userids, ",");
        Console.log("移动案场检查语句");
        Console.log("SELECT * from dh_crm_saleruser u where u.userid in ({});",useridStr);

        System.out.println("=================================================");
        Console.log("客户中心需要补的数据：{}" , centerLessUsers.size());
        Console.log("customer_id\tmobile\tcustomerchannel\tprojectid\tsale_org_id\tsale_team_id\tcreate_time\tvisit_first_date\tupdate_time");
        centerLessUsers.forEach(System.out::println);
        Console.log("=================================================");
        Console.log("客户中心更新到访时间的语句：");
        ydacUserSql.forEach(System.out::println);

    }

    @Test
    public void testQuit() throws SQLException {
        List<Entity> centerResult = Db.use(DB_CENTER).query("select * from sale_consultant where dimission_flag = 0");
        List<Entity> ydacResult = Db.use(DB_YDAC).query("select * from dh_project_saler");

        Map<String,Integer> centerMap = new HashMap<>();
        centerResult.forEach(item -> {
            centerMap.put(item.getStr("user_key"),item.getInt("is_assignment"));
        });

        List<List<Object>> rows = new ArrayList<>();
        Console.log("userkey\tydac_quit\tcenter_is_assignment");
        rows.add(CollUtil.newArrayList("userkey", "ydac_quit（1：离职，0：未离职）", "center_is_assignment（1：可分配，0：不可分配）"));
        ydacResult.forEach(item -> {
            String userkey = item.getStr("userkey");
            if (centerMap.containsKey(userkey)) {
                int is_assignment = centerMap.get(userkey);
                int quit = item.getInt("quit");
                if (quit == is_assignment) {
                    Console.log("{}\t{}\t{}",userkey,quit,is_assignment);
                    rows.add(CollUtil.newArrayList(userkey, quit, is_assignment));
                }
            }
        });
        ExcelWriter writer = new ExcelWriter("D:/temp/output/testQuit.xls");
        writer.write(rows, true);
        //关闭writer，释放内存
        writer.close();
    }

    @Test
    public void generateMsgData() throws SQLException {

        String mobileStr = getMobileFilter();
        String newSql = StrUtil.format("SELECT * from g_error_log l where l.appid = 'syncCustomerCenterDataTopic' and openid in ({}) order by id", mobileStr);
        List<Entity> ydacResult = Db.use(DB_YDAC).query(newSql);

        //使用有序的map，这样同样的操作，只会保存最新的
        LinkedHashMap<String,String> linkedHashMap = new LinkedHashMap();

        ydacResult.forEach(item -> {
            String msgId = item.getStr("mark");
            if (msgId.length() > 32) {
                Console.error("过滤掉重发的消息：{}-{}",item.getStr("openid"),msgId);
            } else {
                JSONObject info = JSONUtil.parseObj(item.getStr("info"));
                String action = info.getStr("action");
                String projectId = item.getStr("projectId");
                String openid = item.getStr("openid");
                String key = StrUtil.format("{}_{}_{}",openid,projectId,action);
                //相同操作，只保留最新的
                linkedHashMap.put(key,item.getStr("info"));
            }
        });

        //输出到文件
        File file = new File("generateMsgData/" + fileName);
        FileUtil.writeLines(linkedHashMap.values(),file, StandardCharsets.UTF_8);
    }

    private String getMobileFilter() {
        List<String> mobileList = FileUtil.readUtf8Lines(getClass().getResource("/mobileFilter.txt"));
        mobileList = mobileList.stream().map(item -> "'" + item + "'").collect(Collectors.toList());
        String mobileStr = CollUtil.join(mobileList, ",");
        return mobileStr;
    }

    /**
     * 同步中台顾问到移动案场
     */
    @Test
    public void synSalerFromCenter() throws SQLException {
        //1000034-3522 上海康桥项目
        //1000087 2355 1110 湛江华发新城市
        //1000062 3528 1210 华发统建锦江大院
        //1000062 3529 1211 华发统建锦江大院
        String saleTeamId = "1000062";
        int projectId = 3529;
        List<Entity> centerResult = Db.use(DB_CENTER).query("SELECT o.customer_opportunity_id,map.customer_id,m.mobile,o.sale_main_id from customer_opportunity o JOIN customer_mobile m on o.customer_opportunity_id=m.customer_opportunity_id " +
                "LEFT JOIN customer_opportunity_map map on o.customer_opportunity_id=map.opportunity_id " +
                "where m.sort = 0 and m.deleted = 0 and o.sale_team_id = ?",saleTeamId);
        List<Entity> ydacResult = Db.use(DB_YDAC).query("select u.saleropenid ,u.id,u.userid,u.mobile from dh_crm_saleruser u where u.projectid = ?",projectId);
        List<Entity> ydacSalerResult = Db.use(DB_YDAC).query("select s.userkey,s.saleropenid from dh_project_saler s where s.userkey is not null");
        Map<String,String> ydacSalerMap = new HashMap<>();
        ydacSalerResult.forEach(item -> ydacSalerMap.put(item.getStr("userkey"),item.getStr("saleropenid")));

        Map<String,String> centerResultMap = new HashMap<>();

        centerResult.forEach(item -> centerResultMap.put(item.getStr("mobile"),item.getStr("sale_main_id")));

        List<String> userNotExistInYdac = new ArrayList<>();
        List<String> salerNotExistInYdac = new ArrayList<>();
        List<String> needUpdateOpenid = new ArrayList<>();
        ydacResult.forEach(item -> {
            String mobile = item.getStr("mobile");
            String centerUserKey = centerResultMap.get(mobile);
            if (centerUserKey == null) {
                userNotExistInYdac.add(mobile);
                return;
            }
            String centerOpenid = ydacSalerMap.get(centerUserKey);
            if (centerOpenid == null) {
                salerNotExistInYdac.add(centerUserKey);
            } else if (!centerOpenid.equals(item.getStr("saleropenid"))){
                needUpdateOpenid.add(StrUtil.format("update dh_crm_saleruser set saleropenid = '{}' where id = {};",centerOpenid,item.getInt("id")));
            }
        });

        Console.log("需要同步中台顾问的记录：");
        needUpdateOpenid.forEach(Console::log);

        //输出到文件
        fileName = DateUtil.format(new Date(), "yyyy-MM-ddHHmmss")+".txt";
        File file = new File("synSalerFromCenter/" + fileName);
        FileUtil.writeLines(needUpdateOpenid,file, StandardCharsets.UTF_8);


        Console.log("移动案场顾问不存在的记录：");
        salerNotExistInYdac.forEach(Console::log);

        Console.log("移动案场客户电话不存在的记录：");
        userNotExistInYdac.forEach(Console::log);
    }
}
